package cn.hnc.checkapi.bean.datatmp;

import cn.hnc.checkapi.bean.Motor;
import cn.hnc.checkapi.bean.Product;
import cn.hnc.checkapi.bean.Servo;
import cn.hnc.checkapi.bean.User;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class TransferProdcutAndDatabean implements Serializable {
   private static final long serialVersionUID = -4774049239286077731L;

   public static Product dataBeanToProduct(DataBean dataBean) {
      Product product = new Product();
      new User();
      product.setId(dataBean.getProductId());
      product.setUploadTime(dataBean.getUploadTime());
      product.setVersion(dataBean.getVersion());
      product.setMacAxNum(dataBean.getMacAxNum());
      product.setPassFlag(dataBean.getPassFlag());
      product.setMacModel(dataBean.getMacModel());
      product.setMacNO(dataBean.getMacNO());
      product.setSysProductTime(dataBean.getSysProductTime());
      product.setMacSN(dataBean.getMacSN());
      product.setMacProductTime(dataBean.getMacProductTime());
      product.setIpcCode(dataBean.getIpcCode());
      product.setContractCode(dataBean.getContractCode());
      product.setCustomerName(dataBean.getCustomerName());
      product.setLoginName(dataBean.getLoginName());
      product.setIoUnitType(dataBean.getIoUnitType());
      product.setIoUnitId(dataBean.getIoUnitId());
      product.setPartCheckFlag(dataBean.getPartCheckFlag());
      product.setSysTypeName(dataBean.getSysTypeName());
      product.setNcVer(dataBean.getNcVer());
      List servos = dataBean.getServos();
      List mServoVerList = dataBean.getmServos();
      List se = new ArrayList();
      List se2 = new ArrayList();
      Iterator var7 = servos.iterator();

      Servo servo;
      while(var7.hasNext()) {
         servo = (Servo)var7.next();
         if (servo.getServoId() != null && !"".equals(servo.getServoId())) {
            se.add(servo);
         }
      }

      var7 = mServoVerList.iterator();

      while(var7.hasNext()) {
         servo = (Servo)var7.next();
         if (servo.getServoId() != null && !"".equals(servo.getServoId())) {
            se2.add(servo);
         }
      }

      product.setServos(se);
      product.setMServoVerList(se2);
      List motors = new ArrayList();
      List motors2 = new ArrayList();
      List elecDatas = dataBean.getElecDatas();
      List mElecDataList = dataBean.getmElecDatas();
      Iterator var11 = elecDatas.iterator();

      ElecData elecData;
      AxServo axServo;
      List nameMinMaxAveCurs;
      Iterator var15;
      NameMinMaxAveCur nameMinMaxAveCur;
      Motor motor;
      while(var11.hasNext()) {
         elecData = (ElecData)var11.next();
         axServo = elecData.getAxServo();
         if ((axServo.getElecId() == null || axServo.getElecModel() == null || "".equals(axServo.getElecId()) || "".equals(axServo.getElecModel())) && (axServo.getServoId() == null || axServo.getServoModel() == null || "".equals(axServo.getServoId()) || "".equals(axServo.getServoModel()))) {
            break;
         }

         nameMinMaxAveCurs = elecData.getNameMinMaxAveCurs();
         var15 = nameMinMaxAveCurs.iterator();

         while(var15.hasNext()) {
            nameMinMaxAveCur = (NameMinMaxAveCur)var15.next();
            motor = new Motor();
            motor.setAxisName(axServo.getAxisName());
            motor.setServoId(axServo.getServoId());
            motor.setElecId(axServo.getElecId());
            motor.setServoModel(axServo.getServoModel());
            motor.setElecModel(axServo.getElecModel());
            motor.setServoProductTime(axServo.getServoProductTime());
            motor.setElecName(nameMinMaxAveCur.getName());
            motor.setMin(nameMinMaxAveCur.getMin());
            motor.setMax(nameMinMaxAveCur.getMax());
            motor.setAverage(nameMinMaxAveCur.getAverage());
            motor.setCur(nameMinMaxAveCur.getCur());
            motors.add(motor);
         }
      }

      product.setMacAxNum(motors.size() / 16);
      var11 = mElecDataList.iterator();

      while(var11.hasNext()) {
         elecData = (ElecData)var11.next();
         axServo = elecData.getAxServo();
         if ((axServo.getElecId() == null || axServo.getElecModel() == null || "".equals(axServo.getElecId()) || "".equals(axServo.getElecModel())) && (axServo.getServoId() == null || axServo.getServoModel() == null || "".equals(axServo.getServoId()) || "".equals(axServo.getServoModel()))) {
            break;
         }

         nameMinMaxAveCurs = elecData.getNameMinMaxAveCurs();
         var15 = nameMinMaxAveCurs.iterator();

         while(var15.hasNext()) {
            nameMinMaxAveCur = (NameMinMaxAveCur)var15.next();
            motor = new Motor();
            motor.setAxisName(axServo.getAxisName());
            motor.setServoId(axServo.getServoId());
            motor.setElecId(axServo.getElecId());
            motor.setServoModel(axServo.getServoModel());
            motor.setElecModel(axServo.getElecModel());
            motor.setServoProductTime(axServo.getServoProductTime());
            motor.setElecName(nameMinMaxAveCur.getName());
            motor.setMin(nameMinMaxAveCur.getMin());
            motor.setMax(nameMinMaxAveCur.getMax());
            motor.setAverage(nameMinMaxAveCur.getAverage());
            motor.setCur(nameMinMaxAveCur.getCur());
            motors2.add(motor);
         }
      }

      motors.addAll(motors2);
      product.setMotors(motors);
      return product;
   }

   public static DataBean productToDataBean(Product product) {
      DataBean dataBean = new DataBean();
      dataBean.setProductId(product.getId());
      dataBean.setUploadTime(product.getUploadTime());
      dataBean.setVersion(product.getVersion());
      dataBean.setMacAxNum(product.getMacAxNum());
      dataBean.setPassFlag(product.getPassFlag());
      dataBean.setMacModel(product.getMacModel());
      dataBean.setMacNO(product.getMacNO());
      dataBean.setSysProductTime(product.getSysProductTime());
      dataBean.setMacSN(product.getMacSN());
      dataBean.setMacProductTime(product.getMacProductTime());
      dataBean.setIpcCode(product.getIpcCode());
      dataBean.setContractCode(product.getContractCode());
      dataBean.setCustomerName(product.getCustomerName());
      dataBean.setLoginName(product.getLoginName());
      dataBean.setIoUnitType(product.getIoUnitType());
      dataBean.setIoUnitId(product.getIoUnitId());
      dataBean.setPartCheckFlag(product.getPartCheckFlag());
      dataBean.setSysTypeName(product.getSysTypeName());
      dataBean.setNcVer(product.getNcVer());
      List<AxServo> servos = product.getServos();
      Collections.sort(servos, (s1, s2) -> {
         return s1.getAxisName().compareTo(s2.getAxisName());
      });
      dataBean.setServos(servos);
      List<AxServo> mServoVerList = product.getMServoVerList();
      Collections.sort(mServoVerList, (s1, s2) -> {
         return s1.getAxisName().compareTo(s2.getAxisName());
      });
      dataBean.setmServos(mServoVerList);
      List motors = product.getMotors();
      List<ElecData> elecDatas = new ArrayList();
      List axServos = new ArrayList();
      List nameMinMaxAveCurss = new ArrayList();
      Map map = new HashMap();
      Iterator var9 = motors.iterator();

      while(var9.hasNext()) {
         Motor motor = (Motor)var9.next();
         String axisName = motor.getAxisName();
         if (!map.containsKey(axisName)) {
            map.put(axisName, map.size());
            axServos.add(new AxServo());
            nameMinMaxAveCurss.add(new ArrayList());
         }

         int i = (Integer)map.get(axisName);
         AxServo axServo = (AxServo)axServos.get(i);
         List nameMinMaxAveCurs = (List)nameMinMaxAveCurss.get(i);
         axServo.setAxisName(motor.getAxisName());
         axServo.setElecId(motor.getElecId());
         axServo.setElecModel(motor.getElecModel());
         axServo.setServoId(motor.getServoId());
         axServo.setServoModel(motor.getServoModel());
         axServo.setServoProductTime(motor.getServoProductTime());
         NameMinMaxAveCur nameMinMaxAveCur = new NameMinMaxAveCur();
         nameMinMaxAveCur.setName(motor.getElecName());
         nameMinMaxAveCur.setAverage(motor.getAverage());
         nameMinMaxAveCur.setCur(motor.getCur());
         nameMinMaxAveCur.setMax(motor.getMax());
         nameMinMaxAveCur.setMin(motor.getMin());
         nameMinMaxAveCurs.add(nameMinMaxAveCur);
      }

      for(int i = 0; i < axServos.size(); ++i) {
         ElecData elecData = new ElecData();
         elecData.setAxServo((AxServo)axServos.get(i));
         elecData.setNameMinMaxAveCurs((List)nameMinMaxAveCurss.get(i));
         elecDatas.add(elecData);
      }

      Collections.sort(elecDatas, (e1, e2) -> {
         return e1.getAxServo().getAxisName().compareTo(e2.getAxServo().getAxisName());
      });
      dataBean.setElecDatas(elecDatas);
      List motors2 = product.getMElecDataList();
      List axServos2 = new ArrayList();
      List<ElecData> mElecDataList = new ArrayList();
      List nameMinMaxAveCurss2 = new ArrayList();
      Map map2 = new HashMap();
      Iterator var28 = motors2.iterator();

      while(var28.hasNext()) {
         Motor motor = (Motor)var28.next();
         String axisName = motor.getAxisName();
         if (!map2.containsKey(axisName)) {
            map2.put(axisName, map2.size());
            axServos2.add(new AxServo());
            nameMinMaxAveCurss2.add(new ArrayList());
         }

         int i = (Integer)map2.get(axisName);
         AxServo axServo = (AxServo)axServos2.get(i);
         List nameMinMaxAveCurs = (List)nameMinMaxAveCurss2.get(i);
         axServo.setAxisName(motor.getAxisName());
         axServo.setElecId(motor.getElecId());
         axServo.setElecModel(motor.getElecModel());
         axServo.setServoId(motor.getServoId());
         axServo.setServoModel(motor.getServoModel());
         axServo.setServoProductTime(motor.getServoProductTime());
         NameMinMaxAveCur nameMinMaxAveCur = new NameMinMaxAveCur();
         nameMinMaxAveCur.setName(motor.getElecName());
         nameMinMaxAveCur.setAverage(motor.getAverage());
         nameMinMaxAveCur.setCur(motor.getCur());
         nameMinMaxAveCur.setMax(motor.getMax());
         nameMinMaxAveCur.setMin(motor.getMin());
         nameMinMaxAveCurs.add(nameMinMaxAveCur);
      }

      for(int i = 0; i < axServos2.size(); ++i) {
         ElecData elecData = new ElecData();
         elecData.setAxServo((AxServo)axServos2.get(i));
         elecData.setNameMinMaxAveCurs((List)nameMinMaxAveCurss2.get(i));
         mElecDataList.add(elecData);
      }

      Collections.sort(mElecDataList, (e1, e2) -> {
         return e1.getAxServo().getAxisName().compareTo(e2.getAxServo().getAxisName());
      });
      dataBean.setmElecDatas(mElecDataList);
      return dataBean;
   }

   public static List dataBeansToProducts(List dataBeans) {
      List ret = new ArrayList();
      Iterator var2 = dataBeans.iterator();

      while(var2.hasNext()) {
         DataBean dataBean = (DataBean)var2.next();
         ret.add(dataBeanToProduct(dataBean));
      }

      return ret;
   }

   public static List productsToDataBeans(List products) {
      List ret = new ArrayList();
      Iterator var2 = products.iterator();

      while(var2.hasNext()) {
         Product product = (Product)var2.next();
         ret.add(productToDataBean(product));
      }

      return ret;
   }
}
